package com.mingtu.guards.adapter;

import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.google.android.material.imageview.ShapeableImageView;
import com.mingtu.common.utils.ConvertLatlng;
import com.mingtu.guards.R;
import com.mingtu.guards.bean.EcDequiBean;

public class EcDequiAdapter extends BaseQuickAdapter<EcDequiBean.DataBean, BaseViewHolder> {

    public EcDequiAdapter() {
        super(R.layout.item_ecology_dequi);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, EcDequiBean.DataBean dataBean) {
        String name = dataBean.getName();
        boolean isOnline = dataBean.isOnline(); //状态 false：离线  true：在线
        String latitude = dataBean.getLat();
        String longitude = dataBean.getLon();
        String address = dataBean.getAddress();
        ShapeableImageView ivPicture = helper.getView(R.id.iv_picture);
        TextView tvOffline = helper.getView(R.id.tv_offline);
        TextView tvOnline = helper.getView(R.id.tv_online);
        if (!StringUtils.isEmpty(name)) {
            helper.setText(R.id.tv_name, name);
            if (name.indexOf("气象") != -1) {
                ivPicture.setBackgroundResource(R.mipmap.img_weather_equi);
            }
            if (name.indexOf("水文") != -1) {
                ivPicture.setBackgroundResource(R.mipmap.img_hydrology_equi);
            }
        }


        if (isOnline) {
            tvOffline.setVisibility(View.GONE);
            tvOnline.setVisibility(View.VISIBLE);
        } else {
            tvOffline.setVisibility(View.VISIBLE);
            tvOnline.setVisibility(View.GONE);
        }

        if (!StringUtils.isEmpty(latitude) && !StringUtils.isEmpty(longitude)) {
            double lng = Double.parseDouble(longitude);
            double lat = Double.parseDouble(latitude);
            String myLng = ConvertLatlng.getInstance().convertToSexagesimal(lng);
            String myLat = ConvertLatlng.getInstance().convertToSexagesimal(lat);
            helper.setText(R.id.tv_lat_lng, "经纬度：" + myLng + "," + myLat);
        }


        if (!StringUtils.isEmpty(address)) {
            helper.setText(R.id.tv_address, "设备位置：" + address);
        }

        helper.addOnClickListener(R.id.layout_nav);
    }

}
